"""Generic form utility functions."""


def form_from_model(form_class, model):
    values = {}
    for attr_name, value in model.get_attributes(include_aliases=True).items():
        if attr_name in form_class.base_fields:
            try:
                values[attr_name] = getattr(model, attr_name)
            except AttributeError:
                pass
    return form_class(values)
